package com.cangshukj.web.controller.junong;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cangshukj.junong.domain.LandNature;
import com.cangshukj.junong.service.ILandNatureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cangshukj.common.annotation.Log;
import com.cangshukj.common.core.controller.BaseController;
import com.cangshukj.common.core.domain.AjaxResult;
import com.cangshukj.common.enums.BusinessType;
import com.cangshukj.junong.domain.LandReginfo;
import com.cangshukj.junong.service.ILandReginfoService;
import com.cangshukj.common.utils.poi.ExcelUtil;
import com.cangshukj.common.core.page.TableDataInfo;

/**
 * 土地流转登记信息Controller
 * 
 * @author wangjie
 * @date 2025-04-01
 */
@Api(value = "/land/reginfo",description = "土地流转登记信息")
@RestController
@RequestMapping("/land/reginfo")
public class LandReginfoController extends BaseController
{
    @Autowired
    private ILandReginfoService landReginfoService;
    @Autowired
    private ILandNatureService landNatureService;

    /**
     * 查询土地流转登记信息列表
     */
    @ApiOperation("查询土地流转登记信息列表")
    @PreAuthorize("@ss.hasPermi('land:reginfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(LandReginfo landReginfo)
    {
        startPage();
        List<LandReginfo> list = landReginfoService.selectLandReginfoList(landReginfo);
        for (LandReginfo info:list){
            String natureId = info.getNatureId();
            LandNature landNature = landNatureService.selectLandNatureByNatureId(natureId);
            if(landNature != null){
                info.setNatureName(landNature.getNatureName());
            }
        }
        clearPage();
        return getDataTable(list);
    }

    /**
     * 获取土地流转登记信息详细信息
     */
    @ApiOperation("获取土地流转登记信息详细信息")
    @PreAuthorize("@ss.hasPermi('land:reginfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        LandReginfo landReginfo = landReginfoService.selectLandReginfoById(id);
        String natureId = landReginfo.getNatureId();
        LandNature landNature = landNatureService.selectLandNatureByNatureId(natureId);
        landReginfo.setNatureName(landNature.getNatureName());
        return AjaxResult.success(landReginfo);
    }

    /**
     * 新增土地流转登记信息
     */
    @ApiOperation("新增土地流转登记信息")
    @PreAuthorize("@ss.hasPermi('land:reginfo:add')")
    @Log(title = "土地流转登记信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LandReginfo landReginfo)
    {
        landReginfo.setCreateBy(getUsername());
        landReginfo.setCreateTime(new Date());
        return toAjax(landReginfoService.insertLandReginfo(landReginfo));
    }

    /**
     * 修改土地流转登记信息
     */
    @ApiOperation("修改土地流转登记信息")
    @PreAuthorize("@ss.hasPermi('land:reginfo:edit')")
    @Log(title = "土地流转登记信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LandReginfo landReginfo)
    {
       landReginfo.setUpdateBy(getUsername());
       landReginfo.setUpdateTime(new Date());
        return toAjax(landReginfoService.updateLandReginfo(landReginfo));
    }

    /**
     * 删除土地流转登记信息
     */
    @ApiOperation("删除土地流转登记信息")
    @PreAuthorize("@ss.hasPermi('land:reginfo:remove')")
    @Log(title = "土地流转登记信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(landReginfoService.deleteLandReginfoByIds(ids));
    }
}
